package com.jesper.seckill.service.mq;

import com.alibaba.fastjson.JSONObject;
import com.jesper.seckill.constant.MqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;

@Service
@Slf4j
public class MQMessageProduceService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 用户秒杀商品成功发送至MQ队列
     */
    public boolean sendSeckillMessageToMQ(JSONObject jsonObject) {
        if (Objects.isNull(jsonObject)) {
            return false;
        }
        rabbitTemplate.convertAndSend(MqConstant.SECKILL_GOODS_ORDER_QUEUE, jsonObject.toString());
        return true;
    }
}
